package com.powernode.cudops;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * @Author Arrebol
 * @Date 2024/7/31 22:14
 * @Project jdbc
 * @Description：
 * 获取连接方法的其他方法，即getConnection的重载方法
 * getConnection(String url)
 * getConnection(String url,Properties info)
 */
public class JdbcTest4 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //获取配置文件中连接数据库的相关信息
        ResourceBundle bundle=ResourceBundle.getBundle("jdbc");
        String driver = bundle.getString("driver");
        String url = bundle.getString("url");
        String user = bundle.getString("user");
        String password = bundle.getString("password");
        Class.forName(driver);
        // jdbc:mysql://localhost:3306/jdbc?user=makangji&password=makangji371526
        String info=url+"?user="+user+"&password="+password;
        System.out.println(info);
        //getConnection(String url)
        Connection conn1 = DriverManager.getConnection(info);
        System.out.println(conn1);
        //getConnection(String url,Properties info)
        Properties properties=new Properties();
        properties.setProperty("user",user);
        properties.setProperty("password",password);
        Connection conn2 = DriverManager.getConnection(url, properties);
        System.out.println(conn2);
    }
}
